package com.d4peng.test.jna;

import com.sun.jna.Callback;
import com.sun.jna.Library;
import com.sun.jna.Native;

import java.io.File;

/**
 * Jna:回调函数
 *
 * @author d4peng
 * @date 2021-11-25
 */
public class JnaDemo5 {

    public interface CallBackOps extends Library {
        public interface CallbackInterface extends Callback {
            void invoke(int val);
        }

        public static class CallbackInterfaceImpl implements CallbackInterface {
            @Override
            public void invoke(int val) {
                System.out.println("callback: " + val);
            }
        }

        public void call_back(CallbackInterface callback);
    }

    public static void main(String[] args) {
        String path = new File("").getAbsoluteFile().getPath() + "\\src\\main\\java\\com\\d4peng\\test\\jna\\c\\callback.dll";
        CallBackOps callBackOps = (CallBackOps) Native.loadLibrary(path, CallBackOps.class);
        callBackOps.call_back(new CallBackOps.CallbackInterfaceImpl());
    }

}
